<?php

/**
 * This is the model class for table "new_data".
 *
 * The followings are the available columns in table 'new_data':
 * @property integer $No
 * @property string $Question
 * @property string $Note
 * @property string $Name
 * @property string $IP
 * @property string $Email
 * @property integer $Reply
 * @property string $ReplyDate
 * @property string $Date
 * @property string $pageview
 */
class NewData extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return NewData the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'new_data';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('Note', 'required'),
			array('Reply', 'numerical', 'integerOnly'=>true),
			array('Question', 'length', 'max'=>100),
			array('Name, Email', 'length', 'max'=>50),
			array('IP', 'length', 'max'=>15),
			array('ReplyDate', 'length', 'max'=>20),
			array('pageview', 'length', 'max'=>5),
			array('Date', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('No, Question, Note, Name, IP, Email, Reply, ReplyDate, Date, pageview', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'No' => 'No',
			'Question' => 'Question',
			'Note' => 'Note',
			'Name' => 'Name',
			'IP' => 'Ip',
			'Email' => 'Email',
			'Reply' => 'Reply',
			'ReplyDate' => 'Reply Date',
			'Date' => 'Date',
			'pageview' => 'Pageview',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('No',$this->No);
		$criteria->compare('Question',$this->Question,true);
		$criteria->compare('Note',$this->Note,true);
		$criteria->compare('Name',$this->Name,true);
		$criteria->compare('IP',$this->IP,true);
		$criteria->compare('Email',$this->Email,true);
		$criteria->compare('Reply',$this->Reply);
		$criteria->compare('ReplyDate',$this->ReplyDate,true);
		$criteria->compare('Date',$this->Date,true);
		$criteria->compare('pageview',$this->pageview,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
           //To Mysql   
    protected function beforeSave() {
       
        $this->Date = date('Y-m-d', CDateTimeParser::parse($this->Date, 'dd/mm/yyyy'));
       
      
        return parent::beforeSave();
    }

// To View
    protected function afterFind() {
        $this->Date = date('d/m/Y', strtotime($this->Date));
        //$this->DEPT_DATE = date('d/m/Y', strtotime($this->DEPT_DATE));
        //$this->DEPT_TIME =date('H:i', strtotime($this->DEPT_TIME));
        
        
        
        return TRUE;
    }
}